home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu563.dms / pu563.adf / MultipleDemo / multipledemo.c < prev    next >
C/C++ Source or Header  |  1994-05-18  |  4KB  |  162 lines

  1. /* Compile me to get full executable. */
  2.  
  3. #include "multipledemoc.c"
  4.  
  5. int done=0;
  6. ULONG count;
  7. UWORD Code;
  8. struct Gadget *Gad;
  9. struct IntuiMessage *imsg;
  10. struct MsgPort *MyMsgPort;
  11. struct WindowNode *WinNode;
  12. struct WindowNode *WinNode2;
  13. struct List WindowList;
  14.  
  15. int OpenNewWin(void)
  16. {
  17. struct WindowNode * WN;
  18. WN=AllocMem(sizeof(struct WindowNode),MEMF_CLEAR);
  19. if (WN !=NULL)
  20.     {
  21.     OpenWindowWinNodeWin( MyMsgPort, WN );
  22.     if (WN->Win==NULL)
  23.         {
  24.         FreeMem(WN,sizeof(struct WindowNode));
  25.         }
  26.     else
  27.         {
  28.         AddTail(&WindowList,(struct Node *)WN);
  29.         WN->Win->UserData=(void *)WN;
  30.         count=0;
  31.         WinNode2=(struct WindowNode *)WindowList.lh_Head;
  32.         while (WinNode2->ln_Succ != NULL)
  33.             {
  34.             count++;
  35.             GT_SetGadgetAttrs(WinNode2->WinGadgets[2],WinNode2->Win, NULL, GTNM_Number, count, TAG_DONE);
  36.             WinNode2=WinNode2->ln_Succ;
  37.             }
  38.         return(0);
  39.         }
  40.     }
  41. return(1);
  42. }
  43.  
  44. void CloseOneWin( struct WindowNode * WN)
  45. {
  46.     Remove((struct Node *)WN);
  47.     CloseWindowWinNodeWin(WN);
  48.     FreeMem(WN,sizeof(struct WindowNode));
  49.     count=0;
  50.     WinNode2=(struct WindowNode *)WindowList.lh_Head;
  51.     while (WinNode2->ln_Succ != NULL)
  52.         {
  53.         count++;
  54.         GT_SetGadgetAttrs(WinNode2->WinGadgets[2],WinNode2->Win, NULL, GTNM_Number, count, TAG_DONE);
  55.         WinNode2=WinNode2->ln_Succ;
  56.         }
  57. }
  58.  
  59. void ProcessMenuIDCMPCommonMenu( UWORD MenuNumber)
  60. {
  61. UWORD MenuNum;
  62. UWORD ItemNumber;
  63. struct MenuItem *item;
  64. while ((MenuNumber != MENUNULL))
  65.     {
  66.     item = ItemAddress( CommonMenu, MenuNumber);
  67.     MenuNum = MENUNUM(MenuNumber);
  68.     ItemNumber = ITEMNUM(MenuNumber);
  69.     switch ( MenuNum )
  70.         {
  71.         case CommonMenu_Options :
  72.             switch ( ItemNumber )
  73.                 {
  74.                 case CommonMenu_Options_Item0 :
  75.                     WinNode=(struct WindowNode *)WindowList.lh_Head;
  76.                     while (WinNode->ln_Succ->ln_Succ != NULL)
  77.                         {
  78.                         CloseOneWin(WinNode);
  79.                         WinNode=(struct WindowNode *)WindowList.lh_Head;
  80.                         }
  81.                     break;
  82.                 case CommonMenu_Options_Item2 :
  83.                     WinNode=(struct WindowNode *)WindowList.lh_Head;
  84.                     while (WinNode->ln_Succ != NULL)
  85.                         {
  86.                         CloseOneWin(WinNode);
  87.                         WinNode=(struct WindowNode *)WindowList.lh_Head;
  88.                         }
  89.                     break;
  90.                 }
  91.             break;
  92.         }
  93.     MenuNumber = item->NextSelect;
  94.     }
  95. }
  96.  
  97. void main(void)
  98. {
  99. ULONG class;
  100. if (OpenLibs()==0)
  101.     {
  102.     NewList(&WindowList);
  103.     OpenDiskFonts();
  104.     if ((MyMsgPort=CreateMsgPort())!=0)
  105.         {
  106.         if (OpenNewWin()==0)
  107.             while(done==0)
  108.                 {
  109.                 Wait(1L << MyMsgPort->mp_SigBit);
  110.                 imsg=GT_GetIMsg(MyMsgPort);
  111.                 while (imsg != NULL )
  112.                     {
  113.                     class=imsg->Class;
  114.                     Code=imsg->Code;
  115.                     Gad=(struct Gadget *)imsg->IAddress;
  116.                     WinNode = (struct WindowNode *)imsg->IDCMPWindow->UserData;
  117.                     GT_ReplyIMsg(imsg);
  118.                     switch ( class )
  119.                         {
  120.                         case IDCMP_GADGETUP :
  121.                             switch ( Gad->GadgetID ) 
  122.                                 {
  123.                                 case CommonWin_Gad0 :
  124.                                     OpenNewWin();
  125.                                     break;
  126.                                 case CommonWin_Gad1 :
  127.                                     OpenNewWin();
  128.                                     OpenNewWin();
  129.                                     OpenNewWin();
  130.                                     OpenNewWin();
  131.                                     OpenNewWin();
  132.                                     break;
  133.                                 }
  134.                             break;
  135.                         case IDCMP_CLOSEWINDOW :
  136.                             CloseOneWin(WinNode);
  137.                             if (WindowList.lh_Head->ln_Succ==NULL)
  138.                               done=1;
  139.                             break;
  140.                         case IDCMP_MENUPICK :
  141.                             ProcessMenuIDCMPCommonMenu( Code );
  142.                             if (WindowList.lh_Head->ln_Succ==NULL)
  143.                               done=1;
  144.                             break;
  145.                         }
  146.                     imsg=GT_GetIMsg(MyMsgPort);
  147.                     }
  148.                 }
  149.         else
  150.             printf("Cannot open window.\n");
  151.         if (CommonMenu != NULL)
  152.           FreeMenus(CommonMenu);
  153.         DeleteMsgPort(MyMsgPort);
  154.         }
  155.     else
  156.         printf("Cannot make message Port.\n");
  157.     CloseLibs();
  158.     }
  159. else
  160.     printf("Cannot open libraries.\n");
  161. }
  162.